package com.xumingxun.aibox.domain.node;

import com.xumingxun.aibox.context.Context;
import com.xumingxun.aibox.domain.var.Var;
import com.xumingxun.aibox.enums.NodeTypeEnum;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public abstract class Node {

    public String id;

    public String nodeName;

    public NodeTypeEnum type;

    public boolean export;

    public List<Var> exportVars=new ArrayList<>();

    public Node next;

    public Context context;

    public Node(Context context){
        this.context=context;
    }

    public void setNextNode(Node nextNode) {
        this.next=nextNode;
    }

    abstract public Node execute();

    abstract public Object getResult();

    abstract public void init();

    public String compileText(String text){
        List<Var> globalVars=context.getGlobalVars();

        return text;
    }

    public Var getVar(String expression) {
        for (Var var : this.exportVars) {
            if (var.getExpression().equals(expression)) {
                return var;
            }
        }
        return null;
    }
}
